package cn.usian.controller;

import cn.usian.pojo.Order;
import cn.usian.pojo.User;
import cn.usian.service.OrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("order")
@CrossOrigin(allowedHeaders = "*")
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private OrderService orderService;

    @RequestMapping("{id}")
    public Order findById(@PathVariable("id") Long id){
        return orderService.findById(id);
    }

    @RequestMapping("findPage")
    public String findPage(@RequestParam(required = true,defaultValue = "1")Integer pageIndex,String name){
        String page=restTemplate.getForObject("http://userservice/user/findPage?pageIndex="+pageIndex+"&name="+name,String.class);
        return page;
    }

    @RequestMapping("add")
    public String add(@RequestBody User user){
        String add=restTemplate.postForObject("http://userservice/user/add",user,String.class);
        return add;
    }

    @RequestMapping("del")
    public String del(Long id){
        Long uid=orderService.findUidById(id);
        String del=restTemplate.getForObject("http://userservice/user/del?id="+id,String.class);
        return del;
    }
}
